home *** CD-ROM | disk | FTP | other *** search
- /* --------------------------------------------------------------------------
- * Copyright 1992 by Forschungszentrum Informatik (FZI)
- *
- * You can use and distribute this software under the terms of the licence
- * you should have received along with this program.
- * If not or if you want additional information, write to
- * Forschungszentrum Informatik, "STONE", Haid-und-Neu-Strasse 10-14,
- * D-7500 Karlsruhe 1, Germany.
- * --------------------------------------------------------------------------
- */
- %token white_space_tok
- %token l_brc_tok
- %token r_brc_tok
- %token double_colon_tok
- %token semi_colon_tok
- %token l_par_tok
- %token r_par_tok
- %token l_br_tok
- %token r_br_tok
- %token operator_string_tok
- %token name_tok
- %token operator_tok
- %token string_tok
- %token char_tok
- %token number_tok
- %token special_tok
-
- %type <c> white_space_tok
- %type <c> l_brc_tok
- %type <c> r_brc_tok
- %type <c> double_colon_tok
- %type <c> semi_colon_tok
- %type <c> l_par_tok
- %type <c> r_par_tok
- %type <c> l_br_tok
- %type <c> r_br_tok
- %type <c> operator_string_tok
- %type <c> name_tok
- %type <c> operator_tok
- %type <c> string_tok
- %type <c> char_tok
- %type <c> number_tok
- %type <c> special_tok
- %type <c> special
-
- %type <s> item
- %type <s> item_except_white_space
- %type <s> item_except_name_stuff
- %type <s> name_stuff
- %type <s> name_dc
- %type <s> name_lp
- %type <s> name_stuff_except_call
- %type <s> name_or_op
- %type <s> name
- %type <s> operator
- %type <s> operator_string
- %type <s> any_except_dclp
- %type <s> any_except_dclpsp
- %type <s> white_space
- %type <s> white_spaces
- %type <s> l_brc
- %type <s> r_brc
-
- %{
-
- #include <malloc.h>
- #include <string.h>
- #include <stream.h>
-
- #include "sys.h"
- #include "smg.h"
- #include "scp_err.h"
- #include "mta_use.h"
- #include "cci_use.h"
- #include "scp_yacc.h"
-
- static sos_Bool global_var_init = FALSE; // 09.07.91 (bs)
- static int nesting = 0;
- static char *in_method_of_sos_class = 0;
- sos_Schema_module scp_mdl;
-
- class string_elem
- { char *s;
- string_elem *next;
- friend class strings;
- friend ostream& operator<< (ostream&, strings&);
- };
-
- class strings
- { string_elem *first, *last;
- friend ostream& operator<< (ostream&, strings&);
- public:
- static strings make (char*);
- char*& operator[](int);
- strings& operator+ (strings&);
- };
-
- strings strings::make (char *s1)
- { strings result;
- result.first=new string_elem;
- result.first->s=s1;
- result.first->next=0;
- result.last=result.first;
- return result;
- }
-
- char*& strings::operator[](int i)
- { string_elem *e = first;
- for (; i; i--) e=e->next;
- return e->s;
- }
-
- strings& strings::operator+ (strings &s1)
- { last->next=s1.first;
- last=s1.last;
- return *this;
- }
-
- static ostream& operator<< (ostream& c, strings &s)
- { string_elem *e, *e1;
- e = s.first;
- for (; e; e=e1)
- { e1 = e->next;
- c << e->s;
- c.flush();
- delete e->s;
- delete e;
- }
- return c;
- }
-
- typedef union {strings s; char *c;} YYSTYPE;
-
- %}
-
- %%
-
- items :
- | items
- item
- { cout << $2; }
- ;
-
- item : item_except_white_space
- | white_space_tok
- { $$=strings::make($1); }
- ;
-
- item_except_white_space : name_stuff
- | item_except_name_stuff
- ;
-
- item_except_name_stuff : l_brc
- | r_brc
- | double_colon_tok
- { $$=strings::make($1); }
- | l_par_tok
- { $$=strings::make($1); }
- | r_par_tok
- { $$=strings::make($1); }
- | string_tok
- { $$=strings::make($1); }
- | char_tok
- { $$=strings::make($1); }
- | number_tok
- { $$=strings::make($1); }
- | special
- { $$=strings::make($1); }
- ;
-
- name_stuff : name_stuff_except_call
- | name_or_op l_par_tok
- { $$ = $1 + strings::make($2); }
- ;
-
- name_dc : name double_colon_tok white_space
- { $$ = $1 + strings::make($2) + $3; }
- ;
-
- name_lp : name_or_op l_par_tok white_space
- { $$ = $1 + strings::make($2) + $3; }
- ;
-
- name_stuff_except_call :
- name_dc name_lp item_except_white_space
- {
- sos_String cn = smg_String ($1[0]).make_String (TEMP_CONTAINER);
- sos_Schema_type tp = scp_mdl.lookup_type (cn, TRUE);
- cn.destroy();
- sos_Bool is_static;
- sos_Bool is_protected;
- sos_Bool is_sos_method = (sos_Bool)(tp != NO_OBJECT
- AND tp.has_type (sos_Class_type_type));
- if (streql ($2[0], "operator"))
- is_static = FALSE;
- else if (is_sos_method)
- { sos_String mn = smg_String ($2[0]).make_String (TEMP_CONTAINER);
- sos_Method_List ml =
- sos_Class_type::make(tp).get_inherited_methods()[mn];
- mn.destroy();
- if (ml == NO_OBJECT)
- { is_static = TRUE;
- is_protected = FALSE;
- }
- else
- { sos_Method m = ml.get_nth(1);
- is_static = m.get_is_static();
- is_protected = (sos_Bool)(m.get_kind() EQ sos_PROTECTED);
- }
- }
- strings result;
- if (is_sos_method)
- { if ((is_static AND nesting != 0 AND NOT is_protected) // 25.8.91 (dt)
- OR global_var_init) // 09.07.91 (bs)
- result = $1 + $2;
- else
- { if (streql ($2[0], "operator"))
- { delete $2[0];
- $2[0] = strdup ("");
- sos_String mn = smg_String ($2[1]).make_String (TEMP_CONTAINER);
- sos_String on = cci_Method_impl::operator_string (mn);
- $2[1] = on.make_Cstring();
- on.destroy();
- mn.destroy();
- }
- result = strings::make (strdup ("_")) + $1 + $2;
- }
- if (NOT is_static)
- { if (nesting == 0)
- { in_method_of_sos_class = strdup ($1[0]);
- result = result +
- strings::make (strdup ("sos_Typed_id &_tpid"));
- }
- else
- result = result + strings::make (strdup ("_tpid"));
- if (NOT streql ($3[0], ")"))
- result = result + strings::make (strdup (","));
- }
- result = result + $3;
- }
- else
- result = $1 + $2 + $3;
- $$ = result;
- }
- | name_dc name_stuff_except_call
- { $$ = $1 + $2; }
- | name_dc item_except_name_stuff
- { $$ = $1 + $2; }
- | name_tok white_space any_except_dclp
- { if (streql ($1, "self") AND in_method_of_sos_class != 0)
- { delete $1;
- $$ = strings::make (strdup (in_method_of_sos_class)) +
- strings::make (strdup ("::make(_tpid,this)")) + $2 + $3;
- }
- else
- $$ = strings::make($1) + $2 + $3;
- }
- | operator any_except_dclpsp
- { $$ = $1 + $2; }
- ;
-
- name_or_op : name
- | operator
- ;
-
- name : name_tok white_space
- { $$ = strings::make($1) + $2; }
- ;
-
- operator : operator_tok operator_string white_space
- { $$ = strings::make($1) + $2 + $3; }
- ;
-
- operator_string :
- white_space operator_string_tok
- { $$ = strings::make ($2) + $1; }
- | white_space l_par_tok white_space r_par_tok
- { $$ = strings::make (strdup ("()")) + $1 + $3;
- delete $2;
- delete $4;
- }
- | white_space l_br_tok white_space r_br_tok
- { $$ = strings::make (strdup ("[]")) + $1 + $3;
- delete $2;
- delete $4;
- }
- | white_space special_tok
- { $$ = strings::make ($2) + $1; }
- | white_space name_tok
- { $$ = strings::make ($2) + $1; }
- ;
-
- any_except_dclp : any_except_dclpsp
- | special
- { $$=strings::make($1); }
- ;
-
- any_except_dclpsp : name_stuff
- | l_brc
- | r_brc
- | r_par_tok
- { $$=strings::make($1); }
- | string_tok
- { $$=strings::make($1); }
- | char_tok
- { $$=strings::make($1); }
- | number_tok
- { $$=strings::make($1); }
- ;
-
- special : operator_string_tok
- { // 09.07.91 (bs)
- if ((nesting == 0) AND ((*$1) == '='))
- global_var_init = TRUE;
- }
- | r_br_tok
- | l_br_tok
- | special_tok
- | semi_colon_tok
- { // 09.07.91 (bs)
- global_var_init = FALSE;
- }
- ;
-
- white_space : { $$ = strings::make (strdup ("")); }
- | white_spaces
- ;
-
- white_spaces : white_space_tok
- { $$ = strings::make($1); }
- | white_spaces white_space_tok
- { $$ = $1 + strings::make($2); }
- ;
-
- l_brc : l_brc_tok
- { nesting++;
- $$=strings::make($1);
- }
- ;
-
- r_brc : r_brc_tok
- { nesting--;
- $$=strings::make($1);
- if (nesting == 0)
- { delete in_method_of_sos_class;
- in_method_of_sos_class = 0;
- }
- }
- ;
-
- %%
-
- extern yyparse ();
-
- void scp_compile ()
- { yyparse ();
- }
-
- void yyerror (char *s) { err_raise (err_USE, s);}
-
- #include "scp_lex.h"
-